﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

public partial class manage : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
       
        Label1.Text = Application["user_name"].ToString();
        Label2.Text = Application["Email"].ToString();
        Label3.Text = Application["Major"].ToString();
        Label4.Text = Application["Gender"].ToString();
        
        

        /*SqlConnection sc = new SqlConnection(source);
        sc.Open();
        SqlCommand com_look = sc.CreateCommand();
        com_look.CommandText = "select Title_Index from favorite where Name_Users=@name";
            com_look.Parameters.Add("@name",SqlDbType.Text);
        com_look.Parameters["@name"]=new SqlParameter("@name",Application["user_name"].ToString());
        SqlDataReader sd=com_look.ExecuteReader();
        while(sd.Read())
        {
            Label8.Text+=sd[0].ToString()+"\n";
        }
        sc.Close();*/
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = Application["user_name"].ToString();
        SqlConnection sc = new SqlConnection(Application["sqlconnection"].ToString());
        sc.Open();
        SqlCommand com_del = sc.CreateCommand();

        com_del.CommandText = "DELETE FROM Users WHERE Name=@name";
        com_del.Parameters.Add("@name", SqlDbType.Text);
        com_del.Parameters["@name"]=new SqlParameter("@name",name);
        int count=com_del.ExecuteNonQuery();
        //if (count == 1)
            //Response.Write("<script language=javascript>alert=('删除成功！')</script>"); 
        sc.Close();

        Application["user_name"] = null;
        Application["query"] = null;
        Application["Email"] = null;
        Application["Gender"] = null;
        Application["Major"] = null;
        Application["password"] = null;
        Application["title"] = null;
        Application["path"] = null;


        //TO-DO 加上从数据库中删除用户信息的代码

        Response.Redirect("login.aspx", true);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("updateuserdata.aspx");
    }
}